package com.ywy.config;

import com.jagregory.shiro.freemarker.ShiroTags;
import com.ywy.templates.HotsTemplate;
import com.ywy.templates.PostsTemplate;
import com.ywy.templates.TimeAgoMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * Freemarker配置
 *
 * @author ywy
 * @date 2021/12/24 18:18
 */
@Configuration
public class FreemarkerConfig {
    @Autowired
    private freemarker.template.Configuration configuration;
    @Autowired
    private TimeAgoMethod timeAgoMethod;
    @Autowired
    private PostsTemplate postsTemplate;
    @Autowired
    private HotsTemplate hotsTemplate;

    @PostConstruct
    public void setUp() {
        // 配置自定义标签
        configuration.setSharedVariable("timeAgo", timeAgoMethod);
        configuration.setSharedVariable("posts", postsTemplate);
        configuration.setSharedVariable("hots", hotsTemplate);
        // shiro标签
        configuration.setSharedVariable("shiro", new ShiroTags());
    }
}
